package o;

import android.util.Pair;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.a;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.util.Arrays;
import java.util.Collections;

public final class agd implements agc {
    private static final double[] ˏ = new double[]{23.976023976023978d, 24.0d, 25.0d, 29.97002997002997d, 30.0d, 50.0d, 59.94005994005994d, 60.0d};
    private final agy ʻ;
    private final boolean[] ʼ;
    private final anc ʽ;
    private long ˊ;
    private long ˊॱ;
    private boolean ˋ;
    private long ˋॱ;
    private String ˎ;
    private long ˏॱ;
    private long ͺ;
    private aef ॱ;
    private boolean ॱˊ;
    private boolean ॱˎ;
    private final e ॱॱ;
    private boolean ॱᐝ;
    private final agl ᐝ;

    static final class e {
        private static final byte[] ˎ = new byte[]{(byte) 0, (byte) 0, (byte) 1};
        public int ˊ;
        public int ˋ;
        public byte[] ˏ;
        private boolean ॱ;

        public e(int i) {
            this.ˏ = new byte[i];
        }

        public void ˋ() {
            this.ॱ = false;
            this.ˊ = 0;
            this.ˋ = 0;
        }

        public boolean ˎ(int i, int i2) {
            if (this.ॱ) {
                this.ˊ -= i2;
                if (this.ˋ == 0 && i == 181) {
                    this.ˋ = this.ˊ;
                } else {
                    this.ॱ = false;
                    return true;
                }
            } else if (i == 179) {
                this.ॱ = true;
            }
            ॱ(ˎ, 0, ˎ.length);
            return false;
        }

        public void ॱ(byte[] bArr, int i, int i2) {
            if (this.ॱ) {
                int i3 = i2 - i;
                if (this.ˏ.length < this.ˊ + i3) {
                    this.ˏ = Arrays.copyOf(this.ˏ, (this.ˊ + i3) * 2);
                }
                System.arraycopy(bArr, i, this.ˏ, this.ˊ, i3);
                this.ˊ = i3 + this.ˊ;
            }
        }
    }

    public agd() {
        this(null);
    }

    public agd(agy o_agy) {
        this.ʻ = o_agy;
        this.ʼ = new boolean[4];
        this.ॱॱ = new e(DnsConfig.MAX_CACHE_ENTRIES);
        if (o_agy != null) {
            this.ᐝ = new agl(178, DnsConfig.MAX_CACHE_ENTRIES);
            this.ʽ = new anc();
            return;
        }
        this.ᐝ = null;
        this.ʽ = null;
    }

    public void ˏ() {
        and.ˏ(this.ʼ);
        this.ॱॱ.ˋ();
        if (this.ʻ != null) {
            this.ᐝ.ˎ();
        }
        this.ˊॱ = 0;
        this.ॱˊ = false;
    }

    public void ˏ(ady o_ady, a aVar) {
        aVar.ˊ();
        this.ˎ = aVar.ˎ();
        this.ॱ = o_ady.ˊ(aVar.ˏ(), 2);
        if (this.ʻ != null) {
            this.ʻ.ˊ(o_ady, aVar);
        }
    }

    public void ˋ(long j, int i) {
        this.ˋॱ = j;
    }

    public void ˊ(anc o_anc) {
        int ˋ = o_anc.ˋ();
        int ॱ = o_anc.ॱ();
        byte[] bArr = o_anc.ˏ;
        this.ˊॱ += (long) o_anc.ˊ();
        this.ॱ.ˎ(o_anc, o_anc.ˊ());
        int i = ˋ;
        while (true) {
            int ॱ2 = and.ॱ(bArr, i, ॱ, this.ʼ);
            if (ॱ2 == ॱ) {
                break;
            }
            int i2 = o_anc.ˏ[ॱ2 + 3] & 255;
            int i3 = ॱ2 - i;
            if (!this.ˋ) {
                if (i3 > 0) {
                    this.ॱॱ.ॱ(bArr, i, ॱ2);
                }
                if (this.ॱॱ.ˎ(i2, i3 < 0 ? -i3 : 0)) {
                    Pair ˏ = ˏ(this.ॱॱ, this.ˎ);
                    this.ॱ.ˎ((Format) ˏ.first);
                    this.ˊ = ((Long) ˏ.second).longValue();
                    this.ˋ = true;
                }
            }
            if (this.ʻ != null) {
                ˋ = 0;
                if (i3 > 0) {
                    this.ᐝ.ˊ(bArr, i, ॱ2);
                } else {
                    ˋ = -i3;
                }
                if (this.ᐝ.ॱ(ˋ)) {
                    this.ʽ.ॱ(this.ᐝ.ॱ, and.ˋ(this.ᐝ.ॱ, this.ᐝ.ˊ));
                    this.ʻ.ˏ(this.ˏॱ, this.ʽ);
                }
                if (i2 == 178 && o_anc.ˏ[ॱ2 + 2] == (byte) 1) {
                    this.ᐝ.ˎ(i2);
                }
            }
            if (i2 == 0 || i2 == 179) {
                int i4 = ॱ - ॱ2;
                if (this.ॱˊ && this.ॱˎ && this.ˋ) {
                    this.ॱ.ˋ(this.ˏॱ, this.ॱᐝ ? 1 : 0, ((int) (this.ˊॱ - this.ͺ)) - i4, i4, null);
                }
                if (!this.ॱˊ || this.ॱˎ) {
                    this.ͺ = this.ˊॱ - ((long) i4);
                    long j = this.ˋॱ != -9223372036854775807L ? this.ˋॱ : this.ॱˊ ? this.ˏॱ + this.ˊ : 0;
                    this.ˏॱ = j;
                    this.ॱᐝ = false;
                    this.ˋॱ = -9223372036854775807L;
                    this.ॱˊ = true;
                }
                this.ॱˎ = i2 == 0;
            } else if (i2 == 184) {
                this.ॱᐝ = true;
            }
            i = ॱ2 + 3;
        }
        if (!this.ˋ) {
            this.ॱॱ.ॱ(bArr, i, ॱ);
        }
        if (this.ʻ != null) {
            this.ᐝ.ˊ(bArr, i, ॱ);
        }
    }

    public void ˋ() {
    }

    private static Pair<Format, Long> ˏ(e eVar, String str) {
        Object copyOf = Arrays.copyOf(eVar.ˏ, eVar.ˊ);
        int i = copyOf[5] & 255;
        int i2 = i >> 4;
        i2 |= (copyOf[4] & 255) << 4;
        int i3 = ((i & 15) << 8) | (copyOf[6] & 255);
        float f = 1.0f;
        switch ((copyOf[7] & 240) >> 4) {
            case 2:
                f = ((float) (i3 * 4)) / ((float) (i2 * 3));
                break;
            case 3:
                f = ((float) (i3 * 16)) / ((float) (i2 * 9));
                break;
            case 4:
                f = ((float) (i3 * 121)) / ((float) (i2 * 100));
                break;
        }
        Format ˏ = Format.ˏ(str, "video/mpeg2", null, -1, -1, i2, i3, SizeModifier.STABLE_STATE_SCALE, Collections.singletonList(copyOf), -1, f, null);
        long j = 0;
        int i4 = (copyOf[7] & 15) - 1;
        if (i4 >= 0 && i4 < ˏ.length) {
            double d = ˏ[i4];
            i4 = eVar.ˋ;
            int i5 = (copyOf[i4 + 9] & 96) >> 5;
            i4 = copyOf[i4 + 9] & 31;
            if (i5 != i4) {
                d *= (((double) i5) + 1.0d) / ((double) (i4 + 1));
            }
            j = (long) (1000000.0d / d);
        }
        return Pair.create(ˏ, Long.valueOf(j));
    }
}
